package com.gigmissions.client;


import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FlowData;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.user.client.Element;

public class AddVenueDialog extends LayoutContainer {
		private MapWidget map;
	
		public AddVenueDialog(MapWidget map){
			
			this.map = map;
			
		}
		
		
	 @Override  
	   protected void onRender(Element parent, int pos) {  
		 
	     super.onRender(parent, pos);  
	    
	     final Dialog complex = constructDialog();
	     	     
	     
	     ButtonBar buttons = new ButtonBar();  
	   
	     buttons.add(new Button("Add Venue..", new SelectionListener<ButtonEvent>() {  
	       public void componentSelected(ButtonEvent ce) {  
	         complex.show();  
	       }  
	     }));  
	     
	    
	   
	     add(buttons, new FlowData(10));
	     
	     
	   } 
		 
		private Dialog constructDialog(){
		
		final Dialog complex = new Dialog();  
		complex.setBodyBorder(false);  
		//complex.setIcon(Examples.ICONS.side_list());  
		complex.setHeading("Add a venue to gig missions:");  
		complex.setWidth(400);  
		complex.setHeight(175);  
		complex.setHideOnButtonClick(false); 
		complex.setButtons(Dialog.OKCANCEL); 
		   
		BorderLayout layout = new BorderLayout();  
		complex.setLayout(layout);  
		   			    		 	     
		final VenueDetailsPanel venuePanel = new VenueDetailsPanel(true,map);   
		BorderLayoutData data = new BorderLayoutData(LayoutRegion.WEST, 150, 100, 250);  
		data.setMargins(new Margins(0, 5, 0, 0));  
		data.setSplit(true);  
		data.setCollapsible(true);  
		data.setFloatable(true);  
		complex.add(venuePanel, data);  
		
		// center  
 
		venuePanel.setHeading("Enter venue details:");
		data = new BorderLayoutData(LayoutRegion.CENTER);  
		complex.add(venuePanel, data);  
		
		Button okButton = complex.getButtonById("ok");
	     
	    okButton.addSelectionListener(new SelectionListener<ButtonEvent>(){

			@Override
			public void componentSelected(ButtonEvent ce) {
				
				  String address = venuePanel.getVenueAddress().getValue();
				  String name = venuePanel.getVenueName().getValue();
				  VenueServiceUtil.geocodeAddressAndShowAddressDialog(name,address,map);
				 
				  
			}
	    	 
	    	 
	     });
		
		
  	    return complex;
			   
			   
	 }

}
